﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using System.Threading;
using Styx;
using Styx.Combat.CombatRoutine;
using Styx.Helpers;
using Styx.Logic;
using Styx.Logic.Combat;
using Styx.Logic.Pathing;
using Styx.WoWInternals;
using Styx.WoWInternals.WoWObjects;
using Styx.Logic.POI;

namespace HarmoniousVigor
{
    public partial class HarmoniousVigorForm : Form
    {
        public HarmoniousVigorForm()
        {
            InitializeComponent();
            Utils.nullCheckSettings();
            Utils.nullCheckCharacterSettings();
        }
        private void UpdateSettingsFromGUI()
        {
            HarmoniousVigor.Settings.enableDeathKnight = enableDeathKnight.Checked;
            HarmoniousVigor.Settings.enableDruid = enableDruid.Checked;
            HarmoniousVigor.Settings.enableHunter = enableHunter.Checked;
            HarmoniousVigor.Settings.enableMage = enableMage.Checked;
            HarmoniousVigor.Settings.enablePaladin = enablePaladin.Checked;
            HarmoniousVigor.Settings.enablePriest = enablePriest.Checked;
            HarmoniousVigor.Settings.enableRogue = enableRogue.Checked;
            HarmoniousVigor.Settings.enableShaman = enableShaman.Checked;
            HarmoniousVigor.Settings.enableWarlock = enableWarlock.Checked;
            HarmoniousVigor.Settings.enableWarrior = enableWarrior.Checked;
            switch (HarmoniousVigor.Me.Class)
            {
                case WoWClass.DeathKnight:
                    DeathKnight.DeathKnightSettings.questingSpec = questingSpec.Text;
                    DeathKnight.DeathKnightSettings.pvpSpec = PVPSpec.Text;
                    DeathKnight.DeathKnightSettings.dungeonSpec = dungeonSpec.Text;
                    break;
                case WoWClass.Druid:
                    Druid.DruidSettings.questingSpec = questingSpec.Text;
                    Druid.DruidSettings.pvpSpec = PVPSpec.Text;
                    Druid.DruidSettings.dungeonSpec = dungeonSpec.Text;
                    break;
                case WoWClass.Hunter:
                    Hunter.HunterSettings.questingSpec = questingSpec.Text;
                    Hunter.HunterSettings.pvpSpec = PVPSpec.Text;
                    Hunter.HunterSettings.dungeonSpec = dungeonSpec.Text;
                    break;
                case WoWClass.Mage:
                    Mage.MageSettings.questingSpec = questingSpec.Text;
                    Mage.MageSettings.pvpSpec = PVPSpec.Text;
                    Mage.MageSettings.dungeonSpec = dungeonSpec.Text;
                    break;
                case WoWClass.Paladin:
                    Paladin.PaladinSettings.questingSpec = questingSpec.Text;
                    Paladin.PaladinSettings.pvpSpec = PVPSpec.Text;
                    Paladin.PaladinSettings.dungeonSpec = dungeonSpec.Text;
                    break;
                case WoWClass.Priest:
                    Priest.PriestSettings.questingSpec = questingSpec.Text;
                    Priest.PriestSettings.pvpSpec = PVPSpec.Text;
                    Priest.PriestSettings.dungeonSpec = dungeonSpec.Text;
                    break;
                case WoWClass.Rogue:
                    Rogue.RogueSettings.questingSpec = questingSpec.Text;
                    Rogue.RogueSettings.pvpSpec = PVPSpec.Text;
                    Rogue.RogueSettings.dungeonSpec = dungeonSpec.Text;
                    break;
                case WoWClass.Shaman:
                    Shaman.ShamanSettings.questingSpec = questingSpec.Text;
                    Shaman.ShamanSettings.pvpSpec = PVPSpec.Text;
                    Shaman.ShamanSettings.dungeonSpec = dungeonSpec.Text;
                    break;
                case WoWClass.Warlock:
                    Warlock.WarlockSettings.questingSpec = questingSpec.Text;
                    Warlock.WarlockSettings.pvpSpec = PVPSpec.Text;
                    Warlock.WarlockSettings.dungeonSpec = dungeonSpec.Text;
                    break;
                case WoWClass.Warrior:
                    Warrior.WarriorSettings.questingSpec = questingSpec.Text;
                    Warrior.WarriorSettings.pvpSpec = PVPSpec.Text;
                    Warrior.WarriorSettings.dungeonSpec = dungeonSpec.Text;
                    break;
            }
        }
        private void UpdateGUIFromSettings()
        {
            enableDeathKnight.Checked = HarmoniousVigor.Settings.enableDeathKnight;
            enableDruid.Checked = HarmoniousVigor.Settings.enableDruid;
            enableHunter.Checked = HarmoniousVigor.Settings.enableHunter;
            enableMage.Checked = HarmoniousVigor.Settings.enableMage;
            enablePaladin.Checked = HarmoniousVigor.Settings.enablePaladin;
            enablePriest.Checked = HarmoniousVigor.Settings.enablePriest;
            enableRogue.Checked = HarmoniousVigor.Settings.enableRogue;
            enableShaman.Checked = HarmoniousVigor.Settings.enableShaman;
            enableWarlock.Checked = HarmoniousVigor.Settings.enableWarlock;
            enableWarrior.Checked = HarmoniousVigor.Settings.enableWarrior;
            switch (HarmoniousVigor.Me.Class)
            {
                case WoWClass.DeathKnight: 
                    questingSpec.Text = DeathKnight.DeathKnightSettings.questingSpec;
                    PVPSpec.Text = DeathKnight.DeathKnightSettings.pvpSpec;
                    dungeonSpec.Text = DeathKnight.DeathKnightSettings.dungeonSpec;
                    break;
                case WoWClass.Druid:
                    questingSpec.Text = Druid.DruidSettings.questingSpec;
                    PVPSpec.Text = Druid.DruidSettings.pvpSpec;
                    dungeonSpec.Text = Druid.DruidSettings.dungeonSpec;
                    break;
                case WoWClass.Hunter:
                    questingSpec.Text = Hunter.HunterSettings.questingSpec;
                    PVPSpec.Text = Hunter.HunterSettings.pvpSpec;
                    dungeonSpec.Text = Hunter.HunterSettings.dungeonSpec;
                    break;
                case WoWClass.Mage: 
                    questingSpec.Text = Mage.MageSettings.questingSpec;
                    PVPSpec.Text = Mage.MageSettings.pvpSpec;
                    dungeonSpec.Text = Mage.MageSettings.dungeonSpec;
                    break;
                case WoWClass.Paladin: 
                    questingSpec.Text = Paladin.PaladinSettings.questingSpec;
                    PVPSpec.Text = Paladin.PaladinSettings.pvpSpec;
                    dungeonSpec.Text = Paladin.PaladinSettings.dungeonSpec;
                    break;
                case WoWClass.Priest: 
                    questingSpec.Text = Priest.PriestSettings.questingSpec;
                    PVPSpec.Text = Priest.PriestSettings.pvpSpec;
                    dungeonSpec.Text = Priest.PriestSettings.dungeonSpec;
                    break;
                case WoWClass.Rogue: 
                    questingSpec.Text = Rogue.RogueSettings.questingSpec;
                    PVPSpec.Text = Rogue.RogueSettings.pvpSpec;
                    dungeonSpec.Text = Rogue.RogueSettings.dungeonSpec;
                    break;
                case WoWClass.Shaman: 
                    questingSpec.Text = Shaman.ShamanSettings.questingSpec;
                    PVPSpec.Text = Shaman.ShamanSettings.pvpSpec;
                    dungeonSpec.Text = Shaman.ShamanSettings.dungeonSpec;
                    break;
                case WoWClass.Warlock: 
                    questingSpec.Text = Warlock.WarlockSettings.questingSpec;
                    PVPSpec.Text = Warlock.WarlockSettings.pvpSpec;
                    dungeonSpec.Text = Warlock.WarlockSettings.dungeonSpec;
                    break;
                case WoWClass.Warrior:
                    questingSpec.Text = Warrior.WarriorSettings.questingSpec;
                    PVPSpec.Text = Warrior.WarriorSettings.pvpSpec;
                    dungeonSpec.Text = Warrior.WarriorSettings.dungeonSpec;
                    break;
            }
        }
        private void saveButtonClick(object sender, EventArgs e)
        {
            UpdateSettingsFromGUI();
            HarmoniousVigor.Settings.Save();
            switch (HarmoniousVigor.Me.Class)
            {
                case WoWClass.DeathKnight:DeathKnight.DeathKnightSettings.Save();break;
                case WoWClass.Druid:Druid.DruidSettings.Save();break;
                case WoWClass.Hunter:Hunter.HunterSettings.Save();break;
                case WoWClass.Mage:Mage.MageSettings.Save();break;
                case WoWClass.Paladin:Paladin.PaladinSettings.Save();break;
                case WoWClass.Priest:Priest.PriestSettings.Save();break;
                case WoWClass.Rogue:Rogue.RogueSettings.Save();break;
                case WoWClass.Shaman:Shaman.ShamanSettings.Save();break;
                case WoWClass.Warlock:Warlock.WarlockSettings.Save();break;
                case WoWClass.Warrior:Warrior.WarriorSettings.Save();break;
            }
            Utils.Log("Settings have been saved");
        }
        private void closeButtonClick(object sender, EventArgs e)
        {

        }
        public void loaded(object sender, EventArgs e)
        {
            Utils.nullCheckSettings();
            Utils.nullCheckCharacterSettings();
            classTabUpdate();
            UpdateGUIFromSettings();            
        }
        public void updateButtonClick(object sender, EventArgs e)
        {
            Updater.CheckForUpdate();
        }
        public void classTabUpdate()
        {
            switch (HarmoniousVigor.Me.Class)
            {
                case WoWClass.DeathKnight: this.classTab.Text = "Death Knight"; break;
                case WoWClass.Druid: this.classTab.Text = "Druid"; break;
                case WoWClass.Hunter: this.classTab.Text = "Hunter"; break;
                case WoWClass.Mage: this.classTab.Text = "Mage"; break;
                case WoWClass.Paladin: this.classTab.Text = "Paladin"; break;
                case WoWClass.Priest: this.classTab.Text = "Priest"; break;
                case WoWClass.Rogue: this.classTab.Text = "Rogue"; break;
                case WoWClass.Shaman: this.classTab.Text = "Shaman"; break;
                case WoWClass.Warlock: this.classTab.Text = "Warlock"; break;
                case WoWClass.Warrior: this.classTab.Text = "Warrior"; break;
            }
        }
        public void questingTabUpdate()
        {
            if (questingSpec.Text == "Primary")
                questingTab.Text = "Questing: " + HarmoniousVigor.primarySpec;
            else
                questingTab.Text = "Questing: " + HarmoniousVigor.secondarySpec;

            /*for (int i = questingTab.Controls.Count; i > 0; i--)
                questingTab.Controls.RemoveAt(i);*/
            Label questingTitleLabel = new Label();
            questingTitleLabel.Anchor = System.Windows.Forms.AnchorStyles.Top;
            questingTitleLabel.Font = new System.Drawing.Font("Microsoft Sans Serif", 14.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            questingTitleLabel.Location = new System.Drawing.Point(195, 9);
            questingTitleLabel.Name = "questingTitleLabel";
            questingTitleLabel.Size = new System.Drawing.Size(282, 24);
            questingTitleLabel.TabIndex = 0;
            if (questingSpec.Text == "Primary")
                questingTitleLabel.Text = "Questing: " + HarmoniousVigor.primarySpec + " Settings";
            else
                questingTitleLabel.Text = "Questing: " + HarmoniousVigor.secondarySpec + " Settings";
            questingTitleLabel.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
            questingTab.Controls.Add(questingTitleLabel);
        }
        public void dungeonTabUpdate()
        {
            if (dungeonSpec.Text == "Primary")
                dungeonTab.Text = "Dungeon: " + HarmoniousVigor.primarySpec;
            else
                dungeonTab.Text = "Dungeon: " + HarmoniousVigor.secondarySpec;

            /*for (int i = dungeonTab.Controls.Count; i > 0; i--)
                dungeonTab.Controls.RemoveAt(i);*/
            Label dungeonTitleLabel = new Label();
            dungeonTitleLabel.Anchor = System.Windows.Forms.AnchorStyles.Top;
            dungeonTitleLabel.Font = new System.Drawing.Font("Microsoft Sans Serif", 14.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            dungeonTitleLabel.Location = new System.Drawing.Point(195, 9);
            dungeonTitleLabel.Name = "dungeonTitleLabel";
            dungeonTitleLabel.Size = new System.Drawing.Size(282, 24);
            dungeonTitleLabel.TabIndex = 0;
            if (dungeonSpec.Text == "Primary")
                dungeonTitleLabel.Text = "Dungeon: " + HarmoniousVigor.primarySpec + " Settings";
            else
                dungeonTitleLabel.Text = "Dungeon: " + HarmoniousVigor.secondarySpec + " Settings";
            dungeonTitleLabel.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
            dungeonTab.Controls.Add(dungeonTitleLabel);
        }
        public void pvpTabUpdate()
        {
            if (PVPSpec.Text == "Primary")
                pvpTab.Text = "PVP: " + HarmoniousVigor.primarySpec;
            else
                pvpTab.Text = "PVP: " + HarmoniousVigor.secondarySpec;

            /*for (int i = pvpTab.Controls.Count; i > 0; i--)
                pvpTab.Controls.RemoveAt(i);*/
            Label pvpTitleLabel = new Label();
            pvpTitleLabel.Anchor = System.Windows.Forms.AnchorStyles.Top;
            pvpTitleLabel.Font = new System.Drawing.Font("Microsoft Sans Serif", 14.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            pvpTitleLabel.Location = new System.Drawing.Point(195, 9);
            pvpTitleLabel.Name = "pvpTitleLabel";
            pvpTitleLabel.Size = new System.Drawing.Size(282, 24);
            pvpTitleLabel.TabIndex = 0;
            if (PVPSpec.Text == "Primary")
                pvpTitleLabel.Text = "PVP: " + HarmoniousVigor.primarySpec + " Settings";
            else
                pvpTitleLabel.Text = "PVP: " + HarmoniousVigor.secondarySpec + " Settings";
            pvpTitleLabel.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
            pvpTab.Controls.Add(pvpTitleLabel);
        }
        private void questingSpecChanged(object sender, EventArgs e)
        {
            questingTabUpdate();
        }
        private void dungeonSpecChanged(object sender, EventArgs e)
        {
            dungeonTabUpdate();
        }
        private void PVPSpecChanged(object sender, EventArgs e)
        {
            pvpTabUpdate();
        }
    }
}
